/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AdminManagerment.jdbc;

import AdminManagerment.entities.Staff;
import AdminManagerment.entities.StaffPoint;
import connection.Configuration;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Tngoc
 */
public class InterviewByScheduler {
    private Staffs staffs;
    private DefaultCategoryDataset data;
    private Configuration config;
    private Connection conn;

    public InterviewByScheduler() {
        config = new Configuration();
        data = new DefaultCategoryDataset();
        staffs = new Staffs();
        getInfo();
    }

    public DefaultCategoryDataset getData() {
        return data;
    }

    public void setData(DefaultCategoryDataset data) {
        this.data = data;
    }
    
    private void getInfo(){
        try {
            conn = config.getConnect();
            CallableStatement cs = conn.prepareCall("{call interviewBySche (?)}");
            for (Staff st : staffs.getStaff(Staffs.SCHEDULER)) {
                cs.setInt(1, st.getID());
                try (ResultSet rs = cs.executeQuery()) {
                    rs.next();
                    StaffPoint sp = new StaffPoint(rs.getString(1), rs.getInt(3), rs.getInt(2));
                    data.setValue(sp.getUnSuccess(), "unsuccess", sp.getName());
                    data.setValue(sp.getSuccess(), "success", sp.getName());
                }
            }
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(InterviewByScheduler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void refresh(){
        data.clear();
        staffs = new Staffs();
        getInfo();
    }
}
